package com.example.wangxinrong.viewmodel;

import androidx.lifecycle.ViewModel;

import com.example.chenzixin.entity.ResultBean;
import com.example.chenzixin.event.SingleLiveEvent;
import com.example.mardan.retrofit.SongciRetrofit;
import com.example.mardan.service.ApiService;
import com.example.wangxinrong.bean.XiaoHuaBean;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class XiaoHuaPicViewModel extends ViewModel {
    private ApiService apiService;

    public SingleLiveEvent<XiaoHuaBean> eventList = new SingleLiveEvent<>();

    public XiaoHuaPicViewModel() {
        this.apiService = SongciRetrofit.getClient("https://api.jisuapi.com/").create(ApiService.class);
    }

    public void getList(int current) {
        Map<String, Object> map = new HashMap<>();
        map.put("pagenum", current);
        map.put("pagesize", 20);
        map.put("sort", "addtime");
        map.put("appkey", "7ddb10c1066f2036");

        apiService.getXiaoHuaPic(map).enqueue(new Callback<ResultBean<XiaoHuaBean>>() {
            @Override
            public void onResponse(Call<ResultBean<XiaoHuaBean>> call, Response<ResultBean<XiaoHuaBean>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    eventList.postValue(response.body().getResult());
                }
            }

            @Override
            public void onFailure(Call<ResultBean<XiaoHuaBean>> call, Throwable throwable) {

            }

        });
    }
}